<?php

try {
    $db = new PDO('mysql:host=80.212.247.167', 'useradmin', 'hig123'); //change to your database settings
    echo "<p>Connected to server</p>";
} catch (PDOException $e) {
    die('Kunne ikke koble til serveren : ' . $e->getMessage());
}

$db->exec('CREATE DATABASE IF NOT EXISTS nettbutikk');

echo "DATABASE nettbutikk created";

$db = null;

try {
    $db = new PDO('mysql:host=80.212.247.167;dbname=nettbutikk', 'useradmin', 'hig123'); //change to your database settings
    echo "<p>Connected to database</p>";
} catch (PDOException $e) {
    die('Kunne ikke koble til serveren : ' . $e->getMessage());
}

$db->exec ('CREATE TABLE IF NOT EXISTS users (uid INT(11) NOT NULL, givenname VARCHAR(32) NOT NULL, surename VARCHAR(32) NOT NULL, address VARCHAR(128) NOT NULL, country INT(11) NOT NULL, postnr char(4) NOT NULL, poststed VARCHAR(128), email VARCHAR(64) NOT NULL, password VARCHAR(32) NOT NULL, type ENUM(\'administrator\',\'user\',\'employee\'), flagged BOOLEAN DEFAULT 0, PRIMARY KEY (`uid`),UNIQUE KEY `email` (`email`))');

echo "<p>Table USERS created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS item (kid INT(11) NOT NULL, vid INT(11) NOT NULL, name VARCHAR(32) NOT NULL, price INT(11) NOT NULL, description BLOB NOT NULL, stock INT(11), picture BLOB NOT NULL, deleted BOOLEAN DEFAULT 0, PRIMARY KEY (`vid`))');

echo "<p>Table ITEM created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS itemCategory (kid INT(11) NOT NULL, name VARCHAR(32) NOT NULL, description BLOB NOT NULL, PRIMARY KEY (`kid`))');

echo "<p>Table ITEMCATEGORY created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS orders (oid INT(11) NOT NULL, uid INT(11) NOT NULL, totalprice INT(11) NOT NULL, orderdate DATETIME NULL, sendingdate DATETIME NULL, PRIMARY KEY (`oid`))');

echo "<p>Table ORDERS created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS orderitems (oid INT(11) NOT NULL, vid INT(11) NOT NULL, originalprice INT(11) NOT NULL, numberof INT(11) NOT NULL)');

echo "<p>Table ORDERITEMS created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS postnr (postnr char(4) NOT NULL, poststed VARCHAR(128) NOT NULL, PRIMARY KEY (`postnr`))');

echo "<p>Table POSTNUMMER created</p>";

$db->exec ('CREATE TABLE IF NOT EXISTS countries (cid INT(11) NOT NULL, country VARCHAR(128), PRIMARY KEY (`cid`))');

echo "<p>Table COUNTRIES created</p>";

echo "<p>Now make uid in USERS AUTO_INCREMENT, vid in items AUTO_INCREMENT, kin in itemcategory AUTO_INCREMENT, oid in ORDERS AUTO_INCREMENT and cid in COUNTRIES AUTO_INCREMENT. Then click on the link under!</p>";

echo "<a href=\"initCP.php\">ADD COUNTRIES AND POSTNUMMER</a>";
?>
